//getTime方法
export function getTime() {
  const nowDate = new Date();
  const date =
    nowDate.getFullYear() +
    "-" +
    _formatNum(nowDate.getMonth() + 1) +
    "-" +
    _formatNum(nowDate.getDate());
  const time =
    _formatNum(nowDate.getHours()) +
    ":" +
    _formatNum(nowDate.getMinutes()) +
    ":" +
    _formatNum(nowDate.getSeconds());
  let week = "";
  switch (nowDate.getDay()) {
    case 0:
      week = "星期天";
      break;
    case 1:
      week = "星期一";
      break;
    case 2:
      week = "星期二";
      break;
    case 3:
      week = "星期三";
      break;
    case 4:
      week = "星期四";
      break;
    case 5:
      week = "星期五";
      break;
    case 6:
      week = "星期六";
      break;
    default:
      break;
  }
  return {
    date,
    time,
    week,
  };
}

function _formatNum(number) {
  return String(number).padStart(2, "0");
}

// 深拷贝-递归
export function deepClone(obj) {
  let objClone = Array.isArray(obj) ? [] : {};

  if (obj && typeof obj === "object") {
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {
        //判断ojb子元素是否为对象，如果是，递归复制

        if (obj[key] && typeof obj[key] === "object") {
          objClone[key] = deepClone(obj[key]);
        } else {
          //如果不是，简单复制

          objClone[key] = obj[key];
        }
      }
    }
  }

  return objClone;
}
